****************************
*********TABLE A2***********
*********CONLEY SE**********
****************************

clear all

set more off
use "${datapath}/fascism_db.dta",clear

* standardize dependent and independent vars
foreach var of varlist fascist_violence-strike_agr_1920 lpop1911-volunteers1866_pop rain1918-rain_var {
egen z_`var'=std(`var')
}

* relabel them
run "labels.do"


***partialling out of the fixed effects to use x_ols and x_gmm
foreach var in fascist_violence fascist_branch fascist1921_vv fascist1924_vv psu1919_vv foots_pop6m lpop1911 lpop2 lpop3 lpop4 sh_pop_1911_be6 larea centre_alt max_alt psu1913_vv ard_vol_pop6m cruent_d veterans74_95 veterans96_00 army_suppliers_d dlab shcrop landlord_ass ind_workers ind_firms literacy elites bourgeoisie {
qui reg z_`var' province* d_reg*
predict r_`var', residuals
}
local cntls_spec1 "r_lpop1911 r_lpop2 r_lpop3 r_lpop4 r_sh_pop_1911_be6"
local cntls_spec4 "`cntls_spec1' r_larea r_centre_alt r_max_alt r_psu1913_vv r_veterans74_95 r_veterans96_00 r_ard_vol_pop6m r_cruent_d r_army_suppliers_d"
local cntls_spec6 "`cntls_spec4' r_dlab r_shcrop r_landlord_ass r_ind_workers r_ind_firms r_literacy r_elites r_bourgeoisie"

gen cutoff1=1.5
gen cutoff2=1.5
	
matrix Table_Conley = J(5,15,.)
*First Stage
foreach i of numlist 1 4 6 {
local x=`x'+1
local wc=wordcount("`cntls_spec`i''")+1
qui x_ols latitude longitude cutoff1 cutoff2 r_psu1919_vv r_foots_pop6m `cntls_spec`i'', xreg(`wc') coord(2)
local se=sqrt(cov_dep[1,1])
matrix Table_Conley[2,`x']= `se'
qui reg r_psu1919_vv r_foots_pop6m `cntls_spec`i'', noconst
local coeff=_b[r_foots_pop6m]
matrix Table_Conley[1,`x']= `coeff'
matrix Table_Conley[5,`x']= (`coeff'/`se')^2

drop dis1 dis2 epsilon window
}
*IV
foreach i of numlist 1 4 6 {
local x=`x'+1
local wc=wordcount("`cntls_spec`i''")+1
qui x_gmm latitude longitude cutoff1 cutoff2 r_fascist_vio r_psu1919_vv `cntls_spec`i'' r_foots_pop6m `cntls_spec`i'' , xreg(`wc') inst(`wc') coord(2)
matrix Table_Conley[3,`x']= betagmm[1,1]
matrix Table_Conley[4,`x']= sqrt(cov_dep[1,1])
drop dis1 dis2 zubar*
}

foreach i of numlist 1 4 6 {
local x=`x'+1
local wc=wordcount("`cntls_spec`i''")+1
qui x_gmm latitude longitude cutoff1 cutoff2 r_fascist_branch r_psu1919_vv `cntls_spec`i'' r_foots_pop6m `cntls_spec`i'' , xreg(`wc') inst(`wc') coord(2)
matrix Table_Conley[3,`x']= betagmm[1,1]
matrix Table_Conley[4,`x']= sqrt(cov_dep[1,1])
drop dis1 dis2 zubar*
}

local x=12
foreach i of numlist 1 4 6 {
local x=`x'+1
local wc=wordcount("`cntls_spec`i''")+1
qui x_gmm latitude longitude cutoff1 cutoff2 r_fascist1924_vv r_psu1919_vv `cntls_spec`i'' r_foots_pop6m `cntls_spec`i'' , xreg(`wc') inst(`wc') coord(2)
matrix Table_Conley[3,`x']= betagmm[1,1]
matrix Table_Conley[4,`x']= sqrt(cov_dep[1,1])
drop dis1 dis2 zubar*
}


drop if z_fascist1921_vv==.

foreach var in fascist_violence fascist_branch fascist1921_vv fascist1924_vv psu1919_vv foots_pop6m lpop1911 lpop2 lpop3 lpop4 sh_pop_1911_be6 larea centre_alt max_alt psu1913_vv ard_vol_pop6m cruent_d veterans74_95 veterans96_00 army_suppliers_d dlab shcrop landlord_ass ind_workers ind_firms literacy elites bourgeoisie {
drop r_`var'
qui reg z_`var' province* d_reg*
predict r_`var', residuals
}
local x=9
foreach i of numlist 1 4 6 {
local x=`x'+1
local wc=wordcount("`cntls_spec`i''")+1
qui x_gmm latitude longitude cutoff1 cutoff2 r_fascist1921_vv r_psu1919_vv `cntls_spec`i'' r_foots_pop6m `cntls_spec`i'' , xreg(`wc') inst(`wc') coord(2)
matrix Table_Conley[3,`x']= betagmm[1,1]
matrix Table_Conley[4,`x']= sqrt(cov_dep[1,1])
drop dis1 dis2 zubar*
}

matrix colnames Table_Conley= "Socialist vote share in 1919" "Socialist vote share in 1919" "Socialist vote share in 1919" "Fascist violence in 1920-2" "Fascist violence in 1920-2" "Fascist violence in 1920-2" "Fascist branches in 1921" "Fascist branches in 1921" "Fascist branches in 1921" "Fascist vote share in 1921" "Fascist vote share in 1921" "Fascist vote share in 1921" "Fascist vote share in 1924" "Fascist vote share in 1924" "Fascist vote share in 1924"
matrix rownames Table_Conley= "Share of footsoldier casualties" "Conley standard error" "Socialist vote share in 1919" "Conley standard error" "1st stage F-stat"

estout matrix(Table_Conley ,fmt(2)) using "${outpath}/TAB_A2.tex", style(tex) replace
